
//
//  OpenDoorView.m
//  YSSmartHome
//
//  Created by yanghao on 2016/10/18.
//  Copyright © 2016年 yahaong. All rights reserved.
//

#import "OpenDoorView.h"
#import "YYImage.h"
#import "YHMarcros.h"

@interface OpenDoorView ()
@property (nonatomic, strong)UIView *m_viewBg;
@property (nonatomic, strong)UIView *m_viewOpenDoor;
@property (nonatomic, strong)UIButton *m_btnExit;
@property (nonatomic, strong)UILabel *m_lblDetail;
@property (nonatomic, strong)UIImageView *m_imgOpenDoor;
@end
@implementation OpenDoorView


#pragma mark - life
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

#pragma mark - setup
- (void)setupUI {
    
    [self addSubview:self.m_viewBg];
    [self.m_viewBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
 
    [self.m_viewBg addSubview:self.m_viewOpenDoor];
    [self.m_viewOpenDoor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.m_viewBg);
        make.width.equalTo(300);
        make.height.equalTo(180);
    }];
    
    [self.m_viewOpenDoor addSubview:self.m_btnExit];
    [self.m_btnExit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.m_viewOpenDoor).offset(10);
        make.trailing.equalTo(self.m_viewOpenDoor).offset(- 10);
    }];
    [self.m_viewOpenDoor addSubview:self.m_imgOpenDoor];
    [self.m_imgOpenDoor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m_viewOpenDoor);
        make.centerY.equalTo(self.m_viewOpenDoor).offset(-10);
        make.width.height.equalTo(70);
    }];
    
    [self.m_viewOpenDoor addSubview:self.m_lblDetail];
    [self.m_lblDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m_viewOpenDoor);
        make.top.equalTo(self.m_imgOpenDoor.bottom).offset(20);
    }];

}


#pragma mark - action
- (void)exitOpenDoor {
    [self removeFromSuperview];
}
#pragma mark - lazy loading

- (UIView *)m_viewBg
{
    if (!_m_viewBg) {
        _m_viewBg = [[UIView alloc]init];
        _m_viewBg.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];

    }
    return _m_viewBg;
}
- (UIView *)m_viewOpenDoor
{
    if (!_m_viewOpenDoor) {
        _m_viewOpenDoor = [[UIView alloc]init];
        _m_viewOpenDoor.backgroundColor = [UIColor whiteColor];
        _m_viewOpenDoor.layer.cornerRadius = 5;
        _m_viewOpenDoor.layer.masksToBounds = YES;
        
    }
    return _m_viewOpenDoor;
}
- (UIImageView *)m_imgOpenDoor
{
    if (!_m_imgOpenDoor) {
        NSString *path = [[NSBundle mainBundle]pathForResource:@"home_open" ofType:@"gif"];
        UIImage *image = [YYImage imageWithContentsOfFile:path];
        _m_imgOpenDoor  = [[YYAnimatedImageView alloc]initWithImage:image];
    }
    return _m_imgOpenDoor;
}
- (UIButton *)m_btnExit
{
    if (!_m_btnExit) {
        _m_btnExit = [UIButton buttonWithType:UIButtonTypeCustom];
        [_m_btnExit setBackgroundImage:[UIImage imageNamed:@"opendoor_icon_exit"] forState:UIControlStateNormal];
        [_m_btnExit addTarget:self action:@selector(exitOpenDoor) forControlEvents:UIControlEventTouchUpInside];
    }
    return _m_btnExit;
}

- (UILabel *)m_lblDetail
{
    if (!_m_lblDetail) {
        _m_lblDetail = [[UILabel alloc]init];
        _m_lblDetail.text = @"距离太远无法正常打开";
        _m_lblDetail.textColor  = RGBColor(51, 51, 51);
    }
    return _m_lblDetail;
}
@end
